package day16;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class OneToManyMap {

	public static void iteratorMap() {
		Map<String, List<Student>> map = new HashMap<String, List<Student>>();
		List<Student> room1 = new ArrayList<Student>();
		List<Student> room2 = new ArrayList<Student>();
		map.put("room1", room1);
		map.put("room2", room2);
		
		room1.add(new Student("zhangsan", 1));
		room1.add(new Student("wangwu", 2));
		room1.add(new Student("zhangyu", 16));
		room1.add(new Student("zhangying", 18));
		
		room2.add(new Student("lisi", 16));
		room2.add(new Student("wangwu", 26));
		room2.add(new Student("zhangyu", 16));
		room2.add(new Student("zhangying", 18));
		
		Set<Entry<String, List<Student>>> entrySet = map.entrySet();
		for (Iterator<Entry<String, List<Student>>> iterator = entrySet
				.iterator(); iterator.hasNext();) {
			Entry<String, List<Student>> entry = iterator.next();
			String room = entry.getKey();
			List<Student> students = entry.getValue();
			System.out.println("room " + room);
			iteratorStudentList(students);
		}
	}

	private static void iteratorStudentList(List<Student> students) {

		for (Iterator<Student> iterator = students.iterator(); iterator
				.hasNext();) {
			Student student = iterator.next();
			System.out.println(student);
		}

	}
	
	public static void main(String[] args) {
		iteratorMap();
	}
}
